<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title>CENTOS安装zookeeper - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="CENTOS安装zookeeper">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content="CENTOS安装zookeeper - 天地维杰网" />
    <meta name="description" content="ZooKeeper是一个分布式的，开放源码的分布式应用程序分布式应用程序协调服务，是Google的Chubby一个开源的实现，是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件，提供的功能包括：配置维护、域名服务、分布式同步、组服务等。" />
     
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/centos-install-zookeeper-and-deploy-zookeeper-cluster/" itemprop="url">
        CENTOS安装zookeeper
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2021-06-01">
    2021-06-01
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/linux" itemprop="url" rel="index">
        <span itemprop="name">linux</span>
      </a>
      &nbsp; 
    </span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/middleware" itemprop="url" rel="index">
        <span itemprop="name">middleware</span>
      </a>
      &nbsp; 
    </span>
  
</span>


      
 <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">转载</span>
</span>

       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">2669 字 ~6分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    <div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback"> 文章系转载，便于整理和分类，原文地址：https://www.cnblogs.com/zpKang/p/13533978.html</code></pre></div>
    

    

<h1 id="centos安装zookeeper及搭建集群">centos安装zookeeper及搭建集群</h1>

<p>ZooKeeper是一个分布式的，开放源码的分布式应用程序分布式应用程序协调服务，是Google的Chubby一个开源的实现，是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件，提供的功能包括：配置维护、域名服务、分布式同步、组服务等。</p>

<p>ZooKeeper的目标就是封装好复杂易出错的关键服务，将简单易用的接口和性能高效、功能稳定的系统提供给用户。</p>

<p>ZooKeeper包含一个简单的原语集，提供Java和C的接口。</p>

<p>ZooKeeper代码版本中，提供了分布式独享锁、选举、队列的接口，代码在$zookeeper_home\src\recipes。其中分布锁和队列有Java和C两个版本，选举只有Java版本。</p>

<p>总结:Zookeeper负责服务的协调调度.当客户端发起请求时,返回正确的服务器地址.</p>

<h2 id="centos安装配置zookeeper">centos安装配置zookeeper</h2>

<h3 id="1-zookeeper下载">1. Zookeeper下载</h3>

<p>网址: <a href="http://zookeeper.apache.org/releases.html">http://zookeeper.apache.org/releases.html</a></p>

<p>其他下载地址: <a href="http://mirrors.hust.edu.cn/apache/zookeeper/">http://mirrors.hust.edu.cn/apache/zookeeper/</a></p>

<h3 id="2-zookeeper安装">2. Zookeeper安装</h3>

<p>安装前提, 确保已经安装了JDK环境 关于jdk的配置: [<a href="https://www.cnblogs.com/zpKang/p/12829419.html">配置jdk]</a></p>

<p>上传安装文件并解压即可, 解压命令 <code>tar -xvf 包名.tar.gz</code></p>

<h3 id="3-修改配置文件">3. 修改配置文件</h3>

<p>在zookeeper解压的根目录下创建两个目录, data和log <code>mkdir data log</code></p>

<p>进入conf目录, 配置文件就在里面, 里面只有一个<code>zoo_sample.cfg</code>的简单位置文件, 我们可以复制一份, 自己修改</p>

<p>假设复制文件名为<code>zoo.cfg</code>, 编辑文件如下</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ini" data-lang="ini"><span style="color:#8f5902;font-style:italic"># 数据目录, 即创建的data目录</span>
<span style="color:#c4a000">dataDir</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">/usr/local/src/zookeeper/data</span>
<span style="color:#8f5902;font-style:italic"># 日志目录, 即创建的log目录</span>
<span style="color:#c4a000">dataLogDir</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">/usr/local/src/zookeeper/log</span>
<span style="color:#8f5902;font-style:italic"># 端口号, 默认2181</span>
<span style="color:#c4a000">clientPort</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">2181</span></code></pre></div>
<h3 id="4-启动zookeeper">4. 启动zookeeper</h3>

<p>跳转到bin目录中 zk启动关闭命令如下.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#8f5902;font-style:italic"># 可以在最后面跟上配置文件的位置, 启动指定配置文件, 不加默认启动zoo.cfg</span>
sh zkServer.sh start     或者  ./zkServer.sh start   
sh zkServer.sh stop
sh zkServer.sh status</code></pre></div>
<h2 id="zookeeper集群搭建">Zookeeper集群搭建</h2>

<p>为了方便测试, 在同一台linux上使用不同端口号代表不同zookeeper主机, 端口号为2181, 2182, 2183</p>

<h3 id="1-准备文件夹">1. 准备文件夹</h3>

<p>在zookeeper根目录下创建zkCluster目录, 此目录为测试集群目录 <code>mkdir zkCluster</code></p>

<p>在zkCluster目录下, 创建zk1, zk2, zk3 目录 <code>mkdir zk1 zk2 zk3</code></p>

<p>分别在zk1, zk2, zk3 目录中创建data和log目录, 快捷指令 <code>mkdir {zk1,zk2,zk3}/{data,log}</code></p>

<h3 id="2-添加myid文件">2. 添加myid文件</h3>

<p><strong>关于myid文件:</strong> myid的值是zoo.cfg文件里定义的server.A项A的值，Zookeeper 启动时会读取这个文件，拿到里面的数据与 zoo.cfg 里面的配置信息比较从而判断到底是那个server，只是一个标识作用。</p>

<p>分别在zk1, zk3, zk2 中创建myid文件, 文件内容分别为 1, 2, 3 数字, 为服务的编号</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220712175419.png" width = 400 /> </div>

<h3 id="3-编辑配置文件">3. 编辑配置文件</h3>

<p>我们首先创建一个配置文件, 修改之后复制三份, 节省时间</p>

<p>进入conf目录, 将zoo_sample.cfg复制为zoo1.cfg, 然后对其进行修改</p>

<p>使用vim等工具打开zoo1.cfg, 修改内容如下:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ini" data-lang="ini"><span style="color:#8f5902;font-style:italic"># 数据目录</span>
<span style="color:#c4a000">dataDir</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">/usr/local/src/zookeeper/zkCluster/zk1/data</span>
<span style="color:#8f5902;font-style:italic"># 日志目录</span>
<span style="color:#c4a000">dataLogDir</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">/usr/local/src/zookeeper/zkCluster/zk1/log</span>
<span style="color:#8f5902;font-style:italic"># 端口号</span>
<span style="color:#c4a000">clientPort</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">2181</span>

<span style="color:#c4a000">tickTime</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">2000</span>
<span style="color:#c4a000">initLimit</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">5</span>
<span style="color:#c4a000">syncLimit</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">2</span>

<span style="color:#8f5902;font-style:italic"># 配置集群</span>
<span style="color:#8f5902;font-style:italic"># server.myid文件编号=ip地址:LF通信端口:选举端口</span>
<span style="color:#8f5902;font-style:italic"># 如果3个zookeeper不在同一台服务器, 通信端口和选举端口一样也没有关系, ip不同即可</span>
<span style="color:#c4a000">server.1</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">192.168.126.129:2887:3887</span>
<span style="color:#c4a000">server.2</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">192.168.126.129:2888:3888</span>
<span style="color:#c4a000">server.3</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">192.168.126.129:2889:3889</span></code></pre></div>
<p>修改完成之后, 我们把此文件再次复制为zoo2.cfg和zoo3.cfg, 然后修改对应的<code>dataDir</code>, <code>dataLogDir</code>, <code>clientPort</code> 即可</p>

<p><strong>关于配置文件的详细介绍如下:</strong></p>

<p>①、tickTime：基本事件单元，这个时间是作为Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔，每隔tickTime时间就会发送一个心跳；最小 的session过期时间为2倍tickTime</p>

<p>②、dataDir：存储内存中数据库快照的位置，除非另有说明，否则指向数据库更新的事务日志。注意：应该谨慎的选择日志存放的位置，使用专用的日志存储设备能够大大提高系统的性能，如果将日志存储在比较繁忙的存储设备上，那么将会很大程度上影像系统性能。</p>

<p>③、client：监听客户端连接的端口。</p>

<p>④、initLimit：允许follower连接并同步到Leader的初始化连接时间，以tickTime为单位。当初始化连接时间超过该值，则表示连接失败。</p>

<p>⑤、syncLimit：表示Leader与Follower之间发送消息时，请求和应答时间长度。如果follower在设置时间内不能与leader通信，那么此follower将会被丢弃。</p>

<p>⑥、server.A=B:C:D</p>

<p>　　A：其中 A 是一个数字，表示这个是服务器的编号；</p>

<p>　　B：是这个服务器的 ip 地址；</p>

<p>　　C：Leader选举的端口；</p>

<p>　　D：Zookeeper服务器之间的通信端口。</p>

<h3 id="4-启动集群">4. 启动集群</h3>

<p>通过下面的命令按顺序启动zk集群 (在bin目录下, 其3个配置文件都在conf目录下)</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">sh zkServer.sh start   ../conf/zoo1.cfg
sh zkServer.sh stop    ../conf/zoo2.cfg
sh zkServer.sh status  ../conf/zoo3.cfg</code></pre></div>
<p>如果启动失败, 说明配置文件有问题, 重新配置修改即可</p>

<p>然后使用 <code>sh zkServer.sh status ../conf/zoo1.cfg</code> 分别检测运行状态</p>

<p>结果如下:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#ce5c00;font-weight:bold">[</span>root@localhost bin<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># sh zkServer.sh status ../conf/zoo1.cfg</span>
ZooKeeper JMX enabled by default
Using config: ../conf/zoo1.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
<span style="color:#ce5c00;font-weight:bold">[</span>root@localhost bin<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># sh zkServer.sh status ../conf/zoo2.cfg</span>
ZooKeeper JMX enabled by default
Using config: ../conf/zoo2.cfg
Client port found: 2182. Client address: localhost.
Mode: leader
<span style="color:#ce5c00;font-weight:bold">[</span>root@localhost bin<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># sh zkServer.sh status ../conf/zoo3.cfg</span>
ZooKeeper JMX enabled by default
Using config: ../conf/zoo3.cfg
Client port found: 2183. Client address: localhost.
Mode: follower</code></pre></div>
<p>如图:</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220712175443.png" width = 500 /> </div>

<p>可见, 按顺序启动后, 2为主机, 1和3为从机,</p>

<p>我们试着把第二台主机关闭(假设宕机) <code>sh zkServer.sh stop ../conf/zoo2.cfg</code></p>

<p>关闭后发现3为主机, 1为从机</p>

<p>这和zookeeper的选举机制有关</p>

<h2 id="zookeeper选举机制">zookeeper选举机制</h2>

<ol>
<li>zk选举采用最大值(myid)优先的机制.</li>
<li>超过半数以上人数同意即可成为领导者(主机)</li>
<li>只有当主机宕机后(心跳检测结果为宕机), 才会重新选举, 即有领导者的时候, 即使新添加了主机, 也不会选举</li>
</ol>

<h3 id="图解">图解</h3>

<p>(按顺序启动1,2,3)</p>

<div  align="center"><img src="https://wejack639.oss-cn-beijing.aliyuncs.com/blogimages/img/20220712175458.png" width = 500 /> </div>

<h3 id="选举案例">选举案例</h3>

<p>目前有5台服务器，每台服务器均没有数据，它们的编号分别是1,2,3,4,5,按编号依次启动，它们的选择举过程如下：</p>

<ul>
<li>服务器1启动，给自己投票，然后发投票信息，由于其它机器还没有启动所以它收不到反馈信息，服务器1的状态一直属于Looking(选举状态)。</li>
<li>服务器2启动，给自己投票，同时与之前启动的服务器1交换结果，由于服务器2的编号大所以服务器2胜出，但此时投票数没有大于半数，所以两个服务器的状态依然是LOOKING。</li>
<li>服务器3启动，给自己投票，同时与之前启动的服务器1,2交换信息，由于服务器3的编号最大所以服务器3胜出，此时投票数正好大于半数，所以服务器3成为领导者，服务器1,2成为小弟。</li>
<li>服务器4启动，给自己投票，同时与之前启动的服务器1,2,3交换信息，尽管服务器4的编号大，但之前服务器3已经胜出，所以服务器4只能成为小弟。</li>
<li>服务器5启动，后面的逻辑同服务器4成为小弟。</li>
</ul>

<p>选举结果: 服务器3为主机</p>

<p>当3宕机, 5为主机,</p>

<p>当5宕机, 4为主机,</p>

<p>当4宕机, 集群彻底崩溃,</p>

<p>1和2永远无法成为主机</p>

    </div>
    <footer class="post-footer">
     
 
<div class="post-tags">     
     
    <a href="http://www.shutdown.cn/tags/linux" rel="tag" title="linux">#linux#</a>
    
    <a href="http://www.shutdown.cn/tags/zookeeper" rel="tag" title="zookeeper">#zookeeper#</a>
    
    <a href="http://www.shutdown.cn/tags/%e9%9b%86%e7%be%a4" rel="tag" title="集群">#集群#</a>
    
    <a href="http://www.shutdown.cn/tags/%e5%88%86%e5%b8%83%e5%bc%8f" rel="tag" title="分布式">#分布式#</a>
    
</div>



     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/jvm-study-03-frequently-used-jvm-params/" rel="next" title="JVM学习03-常用Java虚拟机参数">
        <i class="fa fa-chevron-left"></i> JVM学习03-常用Java虚拟机参数
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/run-redis-with-docker-/" rel="prev" title="docker启动Redis并设置密码">
        docker启动Redis并设置密码 <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

  <ul class="sidebar-nav motion-element">
    <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
      文章目录
    </li>
    <li class="sidebar-nav-overview" data-target="site-overview">
      站点概览
    </li>
  </ul>

    <section class="site-overview sidebar-panel ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
<section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
    <div class="post-toc">
        <div class="post-toc-content"><nav id="TableOfContents">
<ul>
<li><a href="#centos安装zookeeper及搭建集群">centos安装zookeeper及搭建集群</a>
<ul>
<li><a href="#centos安装配置zookeeper">centos安装配置zookeeper</a>
<ul>
<li><a href="#1-zookeeper下载">1. Zookeeper下载</a></li>
<li><a href="#2-zookeeper安装">2. Zookeeper安装</a></li>
<li><a href="#3-修改配置文件">3. 修改配置文件</a></li>
<li><a href="#4-启动zookeeper">4. 启动zookeeper</a></li>
</ul></li>
<li><a href="#zookeeper集群搭建">Zookeeper集群搭建</a>
<ul>
<li><a href="#1-准备文件夹">1. 准备文件夹</a></li>
<li><a href="#2-添加myid文件">2. 添加myid文件</a></li>
<li><a href="#3-编辑配置文件">3. 编辑配置文件</a></li>
<li><a href="#4-启动集群">4. 启动集群</a></li>
</ul></li>
<li><a href="#zookeeper选举机制">zookeeper选举机制</a>
<ul>
<li><a href="#图解">图解</a></li>
<li><a href="#选举案例">选举案例</a></li>
</ul></li>
</ul></li>
</ul>
</nav></div>
    </div>
</section>

  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>